package com.stronger.leetcode.top100;

import com.stronger.leetcode.simple.InsertSite35;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Created by njy on 2023/6/28
 */
public class TowNumsSum1 {


    public static int[] twoSum(int[] nums,int target){
        //给定一个数组和一个目标值，如果数组中有两个值之和等于target，那么返回这两个值的下标，否则返回null；
        if(nums.length==0 || nums.length==1){
            return null;
        }

        //key 值  val 下标
        Map<Integer,Integer> map= new HashMap<>();

        for (int i = 0; i < nums.length; i++) {
            if(map.containsKey(target-nums[i])){
                return new int[]{i,map.get(target-nums[i])};
            }
            map.put(nums[i],i);
        }

        return null;
    }


    public static void main(String[] args) {
        int[] a=new int[]{1,2,5,6,3};
        int[] ints = twoSum(a, 10);
        for (int anInt : ints) {
            System.out.println("ints = " + anInt);
        }

    }
}
